
import os.path as path
import os
import sys

if __name__ == '__main__':
    src = path.normpath(os.getcwd())
    shared = path.normpath(os.path.join(src, 'shared'))
    frontend = path.normpath(os.path.join(src, 'frontend'))
    backend  = path.normpath(os.path.join(src, 'backend'))

    for p in [src, shared, frontend, backend]:
        if p not in sys.path:
            sys.path.append(p)

import socket
import client
import proxy_receiver
import proxy_sender
import game_thread

import wx
import random

g_client = (None, None)
g_game_id = 'game 0'

def launch_thread(factory, *args):
    t = factory(*args)
    tq = t.in_q
    t.start()
    return (t, tq)

def join_thread((t, tq)):
    t.join

def ntfy(dest, *args):
    game_thread.GameThread.ntfy(dest[1], *args)


#-----------------------------------------------------------------
#Class that contains name and bitmap information about a card.
class Card:
    def __init__(self, name, fileName, smallFileName):
        self.cardName = name
        self.cardBitmap = wx.Bitmap(fileName)
        self.smallCardBitmap = wx.Bitmap(smallFileName)

    def getCardName(self):
        return self.cardName

    def getSmallCardBitmap(self):
        return self.smallCardBitmap

    def getCardBitmap(self):
        return self.cardBitmap

                
#-----------------------------------------------------------------
#Panel for holding card
class CardPanel(wx.Panel):
    def __init__(self, parent, pos):
        wx.Panel.__init__(self, parent, pos=pos, size=(80, 128), style=wx.SIMPLE_BORDER)
        self.cardStaticBitmap = wx.StaticBitmap(parent, pos=pos, size=(80, 128), style=wx.SIMPLE_BORDER)
        self.card = -1
        self.isEmptyOfCard = True
        
    def addCard(self, c):
        self.card = c
        self.isEmptyOfCard = False
        
    def getCardStaticBitmap(self):
        return self.cardStaticBitmap

    def getCard(self):
        return self.card

#-----------------------------------------------------------------
#Location within a Place.
class Location(wx.Panel):
    def __init__(self, parent, pos):
        wx.Panel.__init__(self, parent, pos=pos, size=(24, 40), style=wx.SIMPLE_BORDER)
        self.locationStaticBitmap = wx.StaticBitmap(parent, pos=pos, size=(24, 40), style=wx.SIMPLE_BORDER)
        self.pieceInLocation = -1
        self.isEmptyOfPiece = True
        self.locationPlace = -1

    def addPieceToLocation(self, p):
        self.pieceInLocation = p
        self.isEmptyOfPiece = False

    def removePieceFromLocation(self):
        self.pieceInLocation = -1;
        self.locationStaticBitmap.SetBitmap(wx.NullBitmap)
        self.isEmptyOfPiece = True

    def getLocationStaticBitmap(self):
        return self.locationStaticBitmap

    def setLocationPlace(self, place):
        self.locationPlace = place

    def getLocationPlace(self):
        return self.locationPlace

    def isEmpty(self):
        return self.isEmptyOfPiece

#-----------------------------------------------------------------            
#Super class for Room, Hallway, and StartingPlace.
class Place(wx.Panel):
    def __init__(self, parent, pos, size, style, name):
        wx.Panel.__init__(self, parent, pos=pos, size=size, style=style, name=name)

        self.name = name
        self.adjacentPlaces = []
        self.pieceLocations = []
        self.weaponLocations = []

    def getAdjacentPlaces(self):
        return self.adjacentPlaces

    def addAdjacentPlace(self, p):
        self.adjacentPlaces.append(p)

    def getPieceLocations(self):
        return self.pieceLocations

    def getPlaceName(self):
        return self.name

#-----------------------------------------------------------------
#Room class contains Location objects in a list.
class Room(Place):
    def __init__(self, parent, pos, name, fileName):
        Place.__init__(self, parent, pos=pos, size=(150, 150), style=wx.SIMPLE_BORDER, name=name)
        self.SetBackgroundColour("#FBB917") #Goldendrod1

        self.pieceLocations = [Location(self, (1, 45)),
                               Location(self, (25, 45)),
                               Location(self, (49, 45)),
                               Location(self, (73, 45)),
                               Location(self, (97, 45)),
                               Location(self, (121, 45)),
                               Location(self, (1, 86)),
                               Location(self, (25, 86)),
                               Location(self, (49, 86)),
                               Location(self, (73, 86)),
                               Location(self, (97, 86)),
                               Location(self, (121, 86))]

        self.roomLocation = Location(self, (25, 4)) #location holding the room bitmap
        rn = wx.StaticText(self, label=name, pos=(50, 14))
        self.roomBitmap = wx.Bitmap(fileName)
        self.roomLocation.locationStaticBitmap.SetBitmap(self.roomBitmap)

#-----------------------------------------------------------------
#Hally class contains a single Location object in a list.
class Hallway(Place):
    def __init__(self, parent, pos):
        Place.__init__(self, parent, pos=pos,
                       size=(50, 50),
                       style=wx.SIMPLE_BORDER,
                       name="Hallway")
        self.SetBackgroundColour("#6698FF") #Sky Blue

        self.pieceLocations = [Location(self, (12, 4))]

#-----------------------------------------------------------------
#StartingPlace class contains a single Location object in a list.
class StartingPlace(Place):
    def __init__(self, parent, pos):
        Place.__init__(self, parent, pos=pos, size=(24, 40), style=wx.NO_BORDER, name="")

        self.pieceLocations = [Location(self, (0, 0))]

#-----------------------------------------------------------------        
#Super class for Pawn and Weapon.
class Piece:
    def __init__(self, name, fileName, statusBar):
        self.pieceName = name
        self.pieceBitmap = wx.Bitmap(fileName)
        self.pieceLocation = -1
        self.piecePlace = -1
        self.statusBar = statusBar

    def setPiecePlace(self, pl):
        self.piecePlace = pl

    def setPieceLocation(self, loc):
        self.pieceLocation = loc

    def setPieceBitmap(self):
        self.pieceLocation.locationStaticBitmap.SetBitmap(self.pieceBitmap)

    def movePieceToPlace(self, pl):
        d = self.getPieceLocation()
        print "d.isEmpty() ", d.isEmpty()
        self.setPiecePlace(pl)
        pieceLocations = pl.getPieceLocations()
        r = random.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 12)
        print r
        for i in range(len(r)):
            if pieceLocations[r[i]].isEmpty():
                self.setPieceLocation(pieceLocations[r[i]])
                self.setPieceBitmap()
                pieceLocations[r[i]].addPieceToLocation(self)
                d.removePieceFromLocation()
                print "d.isEmpty() ", d.isEmpty()
                break

    def getPiecePlace(self):
        return self.piecePlace

    def getPieceName(self):
        return self.pieceName

    def getPieceLocation(self):
        return self.pieceLocation

    def getPieceBitmap(self):
        return self.pieceBitmap

#-----------------------------------------------------------------
#Pawn class.  It contain information whether it has a player.
class Pawn(Piece):
    def __init__(self, name, fileName, statusBar):
        Piece.__init__(self, name, fileName, statusBar)


        self.hasMoved = False
        self.pawnPlayer = -1

    def setPawnPlayer(self, player):
        self.pawnPlayer = player

    def getPawnPlayer(self):
        return self.pawnPlayer
    
#-----------------------------------------------------------------
#Weapon class.  
class Weapon(Piece):
    def __init__(self, name, fileName, statusBar):
        Piece.__init__(self, name, fileName, statusBar)
        
#-----------------------------------------------------------------
#For drag&drop.
class PieceDataObject(wx.BitmapDataObject):
    def __init__(self, piece):
        wx.BitmapDataObject.__init__(self, piece)

#-----------------------------------------------------------------
#Drop target for Pawn object's bitmap.
class PawnDropTarget(wx.PyDropTarget):
    def __init__(self, loc, pawn, rooms):
        wx.DropTarget.__init__(self)
        self.loc = loc
        self.pawn = pawn
        self.rooms = rooms

        self.data = PieceDataObject(wx.NullBitmap)
        self.SetDataObject(self.data)

    #Things to do when the bitmap is dropped.    
    def OnData(self, x, y, data):
        self.GetData()

        d = self.pawn.getPieceLocation()
        
        self.pawn.setPieceLocation(self.loc)
        self.pawn.setPieceBitmap()
        loc = self.pawn.getPieceLocation()
        loc.addPieceToLocation(self.pawn)
        p = loc.getLocationPlace()
        self.pawn.setPiecePlace(p)
        d.removePieceFromLocation()
        self.pawn.hasMoved = True
        placeName = self.pawn.getPiecePlace().getPlaceName()
        roomNames = []
        for i in range(len(self.rooms)):
            roomNames.append(self.rooms[i].getPlaceName())
        if placeName in roomNames:
            self.pawn.getPawnPlayer().makeSuggestion()
                        
#-----------------------------------------------------------------
# Player class contains information about the game and player operations.
class Player:
    def __init__(self, startingPlaces, hallways, rooms, weapons, pawns, playerPawnIndex, cards, accuseButton, suspectCards, roomCards, weaponCards, caseFile):
        self.playerPawn = pawns[playerPawnIndex]  #Player's character pawn.
        self.playerCards = cards  #Player's cards.
        self.startingPlaces = startingPlaces   #Player's starting place.
        self.hasMadeAnFalseAccusation = False
        self.accuseButton = accuseButton
        self.joined = False
        self.caseFile = caseFile

        #Game states.
        self.rooms = rooms
        self.hallways = hallways
        self.pawns = pawns
        self.weapons = weapons

        #Game cards.
        self.suspectCards = suspectCards
        self.roomCards = roomCards
        self.weaponCards = weaponCards
        
    def setFalseAccusation(self):
        self.hasMadeAnFalseAccusation = True

    def isJoined(self):
        self.joined = True
    
    #For active player.
    def SetAccuseButtonAvailable(self):
        self.accuseButton.Bind(wx.EVT_BUTTON, self.OnAccuse)

    def OnAccuse(self, event):
        print "Make an accusation."
        a = AccusationDialog(None, -1, 'Make an Accusation', self.caseFile, self.playerPawn)
        a.ShowModal()
        a.Destroy()
        return True

    #For active player.
    def SetAdjacentPlacesToMove(self):
        playerPlace = self.playerPawn.getPiecePlace()
        adjacentPlaces = playerPlace.getAdjacentPlaces()

        #Set multiple drop targets.
        for i in range(len(adjacentPlaces)):
            pieceLocations = adjacentPlaces[i].getPieceLocations()
            for j in range(len(pieceLocations)):
                if pieceLocations[j].isEmptyOfPiece == True:
                    q = PawnDropTarget(pieceLocations[j], self.playerPawn, self.rooms)
                    pieceLocations[j].SetDropTarget(q)

        self.playerPawn.pieceLocation.Bind(wx.EVT_MOTION, self.OnStartDrag)          

    def OnStartDrag(self, event):
        if event.Dragging():
            pdo = PieceDataObject(self.playerPawn.pieceBitmap)
            dropSource = wx.DropSource(self.playerPawn.pieceLocation)
            dropSource.SetData(pdo)
            result = dropSource.DoDragDrop()

    def getPlayerCards(self):
        return self.playerCards

    def getSuspectCards(self):
        return self.suspectCards

    def getRoomCards(self):
        return self.roomCards

    def getWeaponCards(self):
        return self.weaponCards

    def getPlayerPawn(self):
        return self.playerPawn

    def getPawns(self):
        return self.pawns

    def getWeapons(self):
        return self.weapons
    
    def makeSuggestion(self):
        print "Make a suggestion."

        d = SuggestionDialog(None, -1, 'Make a Suggestion', self)
        d.ShowModal()
        d.Destroy()
        return True

    def respondToSuggestion(self, suggestion, player, announcement):  #player is the one who is making the suggestion.
        print "Respond to a suggestion."
        opponentCards = self.playerCards
        opponentName = self.playerPawn.getPieceName()
        
        d = ResponseDialog(None, -1, 'Respond to Suggestion', opponentCards, suggestion, player, announcement, opponentName)
        d.ShowModal()
        d.Destroy()
        return True

    def receiveSuggestionResponse(self, opponentName, text):
        d = SuggestionResponseMessage(None, -1, "Respons to suggestion", opponentName, text, self.suspectCards, self.roomCards, self.weaponCards)
        d.ShowModal()
        d.Destroy()
        return True
#-----------------------------------------------------------------        
#Dialog when accusation button is pressed.
class AccusationDialog(wx.Dialog):
    def __init__(self, parent, id, title, caseFile, playerPawn):
        wx.Dialog.__init__(self, parent, id, title, size=(580, 280))

        self.caseFile = caseFile
        self.playerPawn = playerPawn

        a1 = "I accuse"
        a2 = "of committing the crime in the"
        a3 = "with the"
        a4 = "."
        st1 = wx.StaticText(self, -1, a1, pos=(20, 170))
        st2 = wx.StaticText(self, -1, a2, pos=(166, 170))
        st3 = wx.StaticText(self, -1, a3, pos=(414, 170))
        st4 = wx.StaticText(self, -1, a4, pos=(544, 170))
              
        transparent = wx.Bitmap('smallCard_Transparent.png')
        panel1 = wx.Panel(self, -1, pos=(69, 30), size=(87, 128),  style=wx.SUNKEN_BORDER)
        self.picture1 = wx.StaticBitmap(panel1)
        self.picture1.SetBitmap(transparent)
        panel1.SetBackgroundColour(wx.BLACK)
        self.images1 = ['smallCard_MissScarlet.png', 'smallCard_ColonelMustard.png', 'smallCard_MrsWhite.png',
                        'smallCard_MrGreen.png', 'smallCard_MrsPeacock.png', 'smallCard_ProfPlum.png']
        self.suspectNames = ['Miss Scarlet', 'Colonel Mustard', 'Mrs. White', 'Mr. Green', 'Mrs. Peacock', 'Professor Plum']
        self.combo1 = wx.ComboBox(self, -1, pos=(62, 166), size=(100, -1), choices=self.suspectNames, style=wx.CB_READONLY)

        panel2 = wx.Panel(self, -1, pos=(317, 30), size=(87, 128),  style=wx.SUNKEN_BORDER)
        self.picture2 = wx.StaticBitmap(panel2)
        self.picture2.SetBitmap(transparent)
        panel2.SetBackgroundColour(wx.BLACK)
        self.images2 = ['smallCard_Study.png', 'smallCard_Hall.png', 'smallCard_Lounge.png',
                        'smallCard_DiningRoom.png', 'smallCard_Kitchen.png', 'smallCard_Ballroom.png',
                        'smallCard_Conservatory.png', 'smallCard_Library.png', 'smallCard_BilliardRoom.png']
        self.roomNames = ['Study', 'Hall', 'Lounge', 'Dining Room', 'Kitchen', 'Ballroom', 'Conservatory', 'Library', 'Billiard Room']
        self.combo2 = wx.ComboBox(self, -1, pos=(310, 166), size=(100, -1), choices=self.roomNames, style=wx.CB_READONLY)

        panel3 = wx.Panel(self, -1, pos=(456, 30), size=(87, 128),  style=wx.SUNKEN_BORDER)
        self.picture3 = wx.StaticBitmap(panel3)
        self.picture3.SetBitmap(transparent)
        panel3.SetBackgroundColour(wx.BLACK)
        self.images3 = ['smallCard_Candlestick.png', 'smallCard_Knife.png', 'smallCard_LeadPipe.png',
                        'smallCard_Revolver.png', 'smallCard_Rope.png', 'smallCard_Wrench.png']
        self.weaponNames = ['Candlestick', 'Knife', 'Lead Pipe', 'Revolver', 'Rope', 'Wrench']
        self.combo3 = wx.ComboBox(self, -1, pos=(456, 166), size=(87, -1), choices=self.weaponNames, style=wx.CB_READONLY)

        self.Bind(wx.EVT_COMBOBOX, self.OnSelect, id=self.combo1.GetId())
        self.Bind(wx.EVT_COMBOBOX, self.OnSelect, id=self.combo2.GetId())
        self.Bind(wx.EVT_COMBOBOX, self.OnSelect, id=self.combo3.GetId())

        wx.Button(self, 1, 'OK', (389, 220))
        self.Bind(wx.EVT_BUTTON, self.OnAccuseOkay, id=1)

        wx.Button(self, 1, 'Cancel', (469, 220))
        self.Bind(wx.EVT_BUTTON, self.OnCancel, id=2)
       
        self.Centre()

    def OnAccuseOkay(self, event):
        print "OnAccuseOkay"
        suspect = self.suspectNames[self.combo1.GetCurrentSelection()]
        print "Suspect is ", suspect
        room = self.roomNames[self.combo2.GetCurrentSelection()]
        print "Room is ", room
        weapon = self.weaponNames[self.combo3.GetCurrentSelection()]
        print "Weapon is ", weapon

        if suspect in self.caseFile and room in self.caseFile and weapon in self.caseFile:
            dial = wx.MessageDialog(None, "You've made a correct accusation. Congratulations!  You've won!", "You've won!", wx.OK | wx.ICON_INFORMATION)
            dial.ShowModal()
        else:
            dial = wx.MessageDialog(None, "You've made an incorrect accusation. You won't be able to make further move.", "Incorrect accusation", wx.OK | wx.ICON_INFORMATION)
            a = self.playerPawn.getPiecePlace().getAdjacentPlaces()
            self.playerPawn.movePieceToPlace(a[0])
            self.playerPawn.getPawnPlayer().setFalseAccusation()
            dial.ShowModal()

        self.Close()
  
    def OnCancel(self, event):
        self.Close()

    def OnSelect(self, event):
        item = event.GetSelection()
        comboId = event.GetId()
        if comboId == self.combo1.GetId():
            self.picture1.SetFocus()
            self.picture1.SetBitmap(wx.Bitmap(self.images1[item]))
        elif comboId == self.combo2.GetId():
            self.picture2.SetFocus()
            self.picture2.SetBitmap(wx.Bitmap(self.images2[item]))
        elif comboId == self.combo3.GetId():
            self.picture3.SetFocus()
            self.picture3.SetBitmap(wx.Bitmap(self.images3[item]))


#-----------------------------------------------------------------
#Suggestion dialog that pops up when a player enters a room.
class SuggestionDialog(wx.Dialog):
    def __init__(self, parent, id, title, player):
        wx.Dialog.__init__(self, parent, id, title, size=(318, 280))

        self.player = player
        self.playerRoom = self.player.getPlayerPawn().getPiecePlace()
        self.playerRoomName = self.playerRoom.getPlaceName()

        self.pawns = self.player.getPawns()
        self.weapons = self.player.getWeapons()
        self.suspectCards = self.player.getSuspectCards()
        self.weaponCards = self.player.getWeaponCards()
        
        d = "I suggest the crime was committed in the %s by " % self.playerRoomName
        print d
        st1 = wx.StaticText(self, -1, d, (20, 155))
        st2 = wx.StaticText(self, -1, "with the ", (137, 179))
        st3 = wx.StaticText(self, -1, ".", (268, 179))
        
       
#        transparent = wx.Bitmap('smallCard_Transparent.png')
        panel1 = wx.Panel(self, -1, pos=(45, 20), size=(87, 128),  style=wx.SUNKEN_BORDER)
        self.picture1 = wx.StaticBitmap(panel1)
        
        panel1.SetBackgroundColour(wx.BLACK)
        
        self.suspectBitmaps = []
        self.suspectNames = []
        for i in range(len(self.suspectCards)):
            self.suspectBitmaps.append(self.suspectCards[i].getSmallCardBitmap())
            self.suspectNames.append(self.suspectCards[i].getCardName())    
        
        self.combo1 = wx.ComboBox(self, -1, pos=(32, 175), size=(100, -1), choices=self.suspectNames, style=wx.CB_READONLY)
        self.picture1.SetBitmap(self.suspectBitmaps[0])
        self.combo1.SetStringSelection(self.suspectNames[0])

        panel2 = wx.Panel(self, -1, pos=(180, 20), size=(87, 128),  style=wx.SUNKEN_BORDER)
        self.picture2 = wx.StaticBitmap(panel2)

        panel2.SetBackgroundColour(wx.BLACK)

        self.weaponBitmaps = []
        self.weaponNames = []
        for i in range(len(self.weaponCards)):
            self.weaponBitmaps.append(self.weaponCards[i].getSmallCardBitmap())
            self.weaponNames.append(self.weaponCards[i].getCardName())    

        
        self.combo2 = wx.ComboBox(self, -1, pos=(180, 175), size=(87, -1), choices=self.weaponNames, style=wx.CB_READONLY)
        self.picture2.SetBitmap(self.weaponBitmaps[0])
        self.combo2.SetStringSelection(self.weaponNames[0])

        self.Bind(wx.EVT_COMBOBOX, self.OnSelect, id=self.combo1.GetId())
        self.Bind(wx.EVT_COMBOBOX, self.OnSelect, id=self.combo2.GetId())

        wx.Button(self, 1, 'OK', (118, 220))
        self.Bind(wx.EVT_BUTTON, self.OnSuggestOkay, id=1)
       
        self.Centre()

    def OnSuggestOkay(self, event):
        room = self.playerRoomName
        suspect = self.suspectNames[self.combo1.GetCurrentSelection()]
        print "Suspect is ", suspect
        weapon = self.weaponNames[self.combo2.GetCurrentSelection()]
        print "Weapon is ", weapon
        playerName = self.player.getPlayerPawn().getPieceName()
        announcement = "%s says: \n I suggest the crime was committed in the %s by %s with the %s." % (playerName, room,  suspect,  weapon)
        print announcement

        suggestion = [room, suspect, weapon]
        print "suggestion = [room,suspect,weapon]", suggestion

        #Move the pawn to the player's room.
        for i in range(len(self.pawns)):
            p = self.pawns[i]
            if suspect == p.getPieceName():
                p.movePieceToPlace(self.playerRoom)
                break
            
        #Move the weapon to the player's room.
        for i in range(len(self.weapons)):
            w = self.weapons[i]
            if weapon == w.getPieceName():
                w.movePieceToPlace(self.playerRoom)
                break
        
        pawns = self.player.getPawns()
        #
        #Each opponent responds to the suggestion.
        #May need to modify in backend.        
        for i in range(len(pawns)):
            opponent = pawns[i].getPawnPlayer()
            selfName = self.player.getPlayerPawn().getPieceName()
            if opponent != -1 and opponent.getPlayerPawn().getPieceName() != selfName:
                opponent.respondToSuggestion(suggestion, self.player, announcement)  #self.player is the one who makes the suggestion
                               
        self.Close()
  
    def OnSelect(self, event):
        item = event.GetSelection()
        comboId = event.GetId()
        if comboId == self.combo1.GetId():
            self.picture1.SetFocus()
            self.picture1.SetBitmap(self.suspectBitmaps[item])
        elif comboId == self.combo2.GetId():
            self.picture2.SetFocus()
            self.picture2.SetBitmap(self.weaponBitmaps[item])

#-----------------------------------------------------------------
#Dialog that prompts player to try proving a suggestion false. 
class ResponseDialog(wx.Dialog):
    def __init__(self, parent, id, title, opponentCards, suggestion, player, announcement, opponentName):
        wx.Dialog.__init__(self, parent, id, title, size=(550, 550))

        self.opponentCards = opponentCards
        self.suggestion = suggestion
        self.player = player # player is the one making the suggestion.
        self.opponentName = opponentName

        r = "Please try to prove the suggestion false by selecting a named card to show %s." % self.player.getPlayerPawn().getPieceName()
        wx.StaticText(self, -1, announcement, (40, 10))
        wx.StaticText(self, -1, r, (40, 50))
        wx.StaticLine(self, pos=(40, 80), size=(450,1))
        wx.StaticLine(self, pos=(40, 260), size=(450,1))
        wx.StaticLine(self, pos=(40, 440), size=(450,1))
        
        self.cardPanels = []  # Cards holder
        self.cardPanels.append(CardPanel(self, (100, 100)))
        self.cardPanels.append(CardPanel(self, (225, 100)))
        self.cardPanels.append(CardPanel(self, (350, 100)))
        self.cardPanels.append(CardPanel(self, (100, 280)))
        self.cardPanels.append(CardPanel(self, (225, 280)))
        self.cardPanels.append(CardPanel(self, (350, 280)))

        #Fill in opponent's cards to cards holder and creat radio buttons
        self.rbs = []
        ps = [(100, 230), (225,230), (350,230), (100,430), (225,430), (350,430)]
        for i in range(len(opponentCards)):
            self.cardPanels[i].addCard(opponentCards[i])
            sb = self.cardPanels[i].getCardStaticBitmap()
            sb.SetBitmap(opponentCards[i].getSmallCardBitmap())
            self.rbs.append(wx.RadioButton(self, label=opponentCards[i].getCardName(), pos=ps[i]))
            if i == 0:
                self.rbs[i].SetWindowStyle(wx.RB_GROUP)
        self.rbs.append(wx.RadioButton(self, label="I have no card named in suggestion.", pos=(100, 450)))

        wx.Button(self, 1, 'OK', (225, 480))
        self.Bind(wx.EVT_BUTTON, self.OnResponseOkay, id=1)
       
        self.Centre()


    def OnResponseOkay(self, event):
        #Backend to be implemented here.
        cards = []
        for i in range(len(self.opponentCards)):
            cards.append(self.opponentCards[i].getCardName())
            print cards[i]
        cardsSet = set(cards)
        suggestionSet = set(self.suggestion)
        
        for i in range(len(self.rbs)):
            r = self.rbs[i].GetValue()
            if r == True:
                text = self.rbs[i].GetLabelText()
                print "text =", text
                print "self.suggestion =", self.suggestion
                if text in self.suggestion:
                    #Message Dialog back to the player.
                    print "%s has a card of %s." %(self.opponentName, text) 
                    self.player.receiveSuggestionResponse(self.opponentName, text)
                    self.Close()
                else:
                    if text == "I have no card named in suggestion.":
                        print cardsSet & suggestionSet
                        #Message Dialog back to the player.
                        if cardsSet.isdisjoint(suggestionSet):
                            self.player.receiveSuggestionResponse(self.opponentName, text)
                            self.Close()
                        else:
                            dial = wx.MessageDialog(None, "Please select a card named in suggestion.", 'Error', wx.OK | wx.ICON_ERROR)
                            dial.ShowModal()
                    else:
                        if cardsSet.isdisjoint(suggestionSet):
                            dial = wx.MessageDialog(None, "Please select 'I have no card named in suggestion.'", 'Error', wx.OK | wx.ICON_ERROR)
                            dial.ShowModal()
                        else:
                            dial = wx.MessageDialog(None, "Please select a card named in suggestion.", 'Error', wx.OK | wx.ICON_ERROR)
                            dial.ShowModal()
                        
#-----------------------------------------------------------------
#Response message box the player who made a suggestion receives.
class SuggestionResponseMessage(wx.Dialog):
    def __init__(self, parent, id, title, opponentName, text, suspectCards, roomCards, weaponCards):
        wx.Dialog.__init__(self, parent, id, title, size=(340, 530))     

        panel = wx.Panel(self, -1, pos=(40, 40), size=(260, 400),  style=wx.SUNKEN_BORDER)
        self.picture = wx.StaticBitmap(panel)
        panel.SetBackgroundColour(wx.BLACK)

        wx.Button(self, 1, 'OK', (140, 460))
        self.Bind(wx.EVT_BUTTON, self.OnOkay, id=1)

        if text == "I have no card named in suggestion.":
            n = "%s has no card named in suggestion." %opponentName
            wx.StaticText(self, -1, n, pos=(40, 10))
        else:
            d = "%s shows you a card of %s." %(opponentName, text)
            st = wx.StaticText(self, -1, d, pos=(40, 10))
            cards = [suspectCards, roomCards, weaponCards]
            b = []
            for i in range(len(cards)):
                for j in range(len(cards[i])):
                    b.append(cards[i][j])      
            for i in range(len(b)):
                if text == b[i].getCardName():
                    self.picture.SetBitmap(b[i].getCardBitmap())
                    break

    def OnOkay(self, event):
        self.Close()
        
#-----------------------------------------------------------------
#Dialog that pops up when the Join menu item in the Game menu is pressed.
class JoinDialog(wx.Dialog):
    def __init__(self, parent, id, title, playerCards, p1, playerCardPanel, playerPawnName, players):
        wx.Dialog.__init__(self, parent, id, title, size=(480, 500))     

        self.playerCards = playerCards
        self.p1 = p1
        self.playerCardPanel = playerCardPanel
        self.playerPawnName = playerPawnName
        self.players = players

        st = wx.StaticText(self, -1, "Please select a character...", pos=(40, 10))
        

        self.rb1 = wx.RadioButton(self, label=playerCards[0].getCardName(), pos=(320, 40), 
            style=wx.RB_GROUP)
        self.rb2 = wx.RadioButton(self, label=playerCards[1].getCardName(), pos=(320, 60))
        self.rb3 = wx.RadioButton(self, label=playerCards[2].getCardName(), pos=(320, 80))
        self.rb4 = wx.RadioButton(self, label=playerCards[3].getCardName(), pos=(320, 100))
        self.rb5 = wx.RadioButton(self, label=playerCards[4].getCardName(), pos=(320, 120))
        self.rb6 = wx.RadioButton(self, label=playerCards[5].getCardName(), pos=(320, 140))

        self.rb1.SetValue(False)

        
        self.rb1.Bind(wx.EVT_RADIOBUTTON, self.OnSelect)
        self.rb2.Bind(wx.EVT_RADIOBUTTON, self.OnSelect)
        self.rb3.Bind(wx.EVT_RADIOBUTTON, self.OnSelect)
        self.rb4.Bind(wx.EVT_RADIOBUTTON, self.OnSelect)
        self.rb5.Bind(wx.EVT_RADIOBUTTON, self.OnSelect)
        self.rb6.Bind(wx.EVT_RADIOBUTTON, self.OnSelect)

       
        self.transparent = wx.Bitmap('Card_Transparent.png')
        panel = wx.Panel(self, -1, pos=(40, 40), size=(260, 400),  style=wx.SUNKEN_BORDER)
        self.picture = wx.StaticBitmap(panel)
        panel.SetBackgroundColour(wx.BLACK)
        self.playerBitmaps = []
        for i in range(len(playerCards)):
            self.playerBitmaps.append(playerCards[i].getCardBitmap())
            
        wx.Button(self, 1, 'OK', (320, 416))
        self.Bind(wx.EVT_BUTTON, self.OnJoinOkay, id=1)
       
        self.Centre()

    def OnSelect(self, e):
        self.states = []
        self.states.append(self.rb1.GetValue())
        self.states.append(self.rb2.GetValue())
        self.states.append(self.rb3.GetValue())
        self.states.append(self.rb4.GetValue())
        self.states.append(self.rb5.GetValue())
        self.states.append(self.rb6.GetValue())

        print "self.states[0] = ", self.states[0]
        print "self.states[1] = ", self.states[1]
        print "self.states[2] = ", self.states[2]
        print "self.states[3] = ", self.states[3]
        print "self.states[4] = ", self.states[4]
        print "self.states[5] = ", self.states[5]


        self.picture.SetBitmap(self.transparent)
        
        if self.states[0]:
            self.picture.SetFocus()
            self.picture.SetBitmap(self.playerBitmaps[0])
        elif self.states[1]:
            self.picture.SetFocus()
            self.picture.SetBitmap(self.playerBitmaps[1])
        elif self.states[2]:
            self.picture.SetFocus()
            self.picture.SetBitmap(self.playerBitmaps[2])
        elif self.states[3]:
            self.picture.SetFocus()
            self.picture.SetBitmap(self.playerBitmaps[3])
        elif self.states[4]:
            self.picture.SetFocus()
            self.picture.SetBitmap(self.playerBitmaps[4])
        elif self.states[5]:
            self.picture.SetFocus()
            self.picture.SetBitmap(self.playerBitmaps[5])
        

    def OnJoinOkay(self, event):
        for i in range(len(self.states)):
            if self.states[i]:        
                sb = self.playerCardPanel.getCardStaticBitmap()
                sb.SetBitmap(self.playerCards[i].getSmallCardBitmap())
                self.playerCardPanel.addCard(self.playerCards[i])

                self.players[i].isJoined()

                ntfy(g_client, 'join_game', g_game_id, self.playerCards[i].getCardName())

                break

        

        self.Close()

import pickle
         
#-----------------------------------------------------------------
#The Game class. setting up the game interface and information about the game.
class GameInterface(wx.Frame):

    def pickle_game(self):
        data = pickle.dumps((self.startingPlaces,                            
                             self.hallways,
                             self.rooms,
                             self.weapons,
                             self.pawns,
                             self.players,
                             self.caseFile,
                             self.playerPawnName))




        print 'Length of pickled data: %s' % len(data)
        return data
        
    
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(1145, 700))

        #Game states

        self.startingPlaces = []
        self.hallways = []
        self.rooms = []
        self.weapons = []
        self.pawns = []
        self.players = []
        self.caseFile = []

        #Player info
        self.playerPawnName = ""

        self.suspectCards = []
        self.roomCards = []
        self.weaponCards = []

        #Setting up game panels
        print "Test"
        self.splitter1 = wx.SplitterWindow(self, -1, style=wx.SP_3DSASH)
        self.splitter2 = wx.SplitterWindow(self.splitter1, -1, style=wx.SP_3DSASH)
        self.p1 = wx.Panel(self.splitter1, -1, style=wx.SUNKEN_BORDER)
        self.p2 = wx.Panel(self.splitter2, -1, style=wx.SUNKEN_BORDER)
        self.p3 = wx.Panel(self.splitter2, -1, style=wx.SUNKEN_BORDER)

        self.splitter1.SplitVertically(self.p1, self.splitter2, 260)
        self.splitter2.SplitVertically(self.p2, self.p3, -260)

        self.p1.SetBackgroundColour("#57E964")
        self.p2.SetBackgroundColour("#57E964")
        self.p3.SetBackgroundColour("#57E964")

        self.sb = self.CreateStatusBar()

        self.gameMenu = wx.Menu()

        self.menuAbout = self.gameMenu.Append(wx.ID_ABOUT, "&About", " Information about the game Clue-Less.")
#        self.menuJoin = self.gameMenu.Append(wx.ID_ANY, "&Join", " Join a new game.")
        self.menuExit = self.gameMenu.Append(wx.ID_EXIT, "E&xit")

        # Creating the menubar.
        self.menuBar = wx.MenuBar()
        self.menuBar.Append(self.gameMenu, "&Game")
        self.SetMenuBar(self.menuBar) 

        self.Bind(wx.EVT_MENU, self.OnAbout, self.menuAbout)
#        self.Bind(wx.EVT_MENU, self.OnJoin, self.menuJoin)
        self.Bind(wx.EVT_MENU, self.OnExit, self.menuExit)

        #Setting up left panel.
        font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
        font.SetPointSize(9)
        vbox1 = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        
        st1 = wx.StaticText(self.p1, label='You are ')
        st2 = wx.StaticText(self.p1, label=self.playerPawnName) 
        st1.SetFont(font)
        st2.SetFont(font)
        hbox1.Add(st1, flag=wx.TOP, border=5)
        hbox1.Add(st2, flag=wx.TOP, border=5)

        vbox1.Add(hbox1, flag=wx.TOP|wx.ALIGN_CENTER, border=5)

        self.playerCardPanel = CardPanel(self.p1, (88, 30))


        vbox1.Add(wx.StaticLine(self.p1, size=(240,1)), flag=wx.TOP|wx.ALIGN_CENTER, border=169)
        self.p1.SetSizer(vbox1)

        st3 = wx.StaticText(self.p1, label='Cards in Hand')
        st3.SetFont(font)
        vbox1.Add(st3, flag=wx.TOP|wx.ALIGN_CENTER, border=10)
        self.p1.SetSizer(vbox1)

        self.cardPanels = []  # Cards holder
        self.cardPanels.append(CardPanel(self.p1, (5, 230)))
        self.cardPanels.append(CardPanel(self.p1, (88, 230)))
        self.cardPanels.append(CardPanel(self.p1, (171, 230)))
        self.cardPanels.append(CardPanel(self.p1, (5, 361)))
        self.cardPanels.append(CardPanel(self.p1, (88, 361)))
        self.cardPanels.append(CardPanel(self.p1, (171, 361)))

        vbox1.Add(wx.StaticLine(self.p1, size=(240,1)), flag=wx.TOP|wx.ALIGN_CENTER, border=312)

        self.hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        self.joinButton = wx.Button(self.p1, pos = (19, 550), size=(60, 30), label="Join")
        self.startButton = wx.Button(self.p1, pos = (98, 550), size=(60, 30), label="Start")
        self.accuseButton = wx.Button(self.p1, pos=(177, 550), size=(60, 30), label='Accuse')

        self.hbox2.Add(self.joinButton, flag=wx.RIGHT, border=20)
        self.hbox2.Add(self.startButton, flag=wx.RIGHT, border=20)
        self.hbox2.Add(self.accuseButton, flag=wx.RIGHT)

        vbox1.Add(self.hbox2, flag=wx.TOP|wx.ALIGN_CENTER, border=16)
#        self.accuseButton.Bind(wx.EVT_BUTTON, self.OnAccuse)

        #Setting up right panel
        vbox2 = wx.BoxSizer(wx.VERTICAL)
        font.SetPointSize(9)

        st2 = wx.StaticText(self.p3, label='Message Box')
        st2.SetFont(font)
        vbox2.Add(st2, flag=wx.TOP|wx.ALIGN_CENTER, border=5)
        vbox2.Add((-1, 8))

        self.messageBox = wx.TextCtrl(self.p3, size=(240, 400),
                                      style = wx.TE_MULTILINE|wx.HSCROLL|
                                      wx.TE_READONLY)
        vbox2.Add(self.messageBox, flag=wx.ALIGN_CENTER)
        vbox2.Add((-1, 6))

        st3 = wx.StaticText(self.p3, label='Chat Box')
        st3.SetFont(font)
        vbox2.Add(st3, flag=wx.TOP|wx.ALIGN_CENTER, border=5)
        vbox2.Add((-1, 5))

        self.chatBox = wx.TextCtrl(self.p3, size=(240, 120),
                                   style=wx.TE_MULTILINE)
        vbox2.Add(self.chatBox, flag=wx.ALIGN_CENTER)

        self.p3.SetSizer(vbox2)



        
        self.Center()
        self.Show()
        self.InitUI()

        data = self.pickle_game()
        print pickle.loads(data)
        
        self.Play()


#-----------------------------------------------------------------
#Initializing the game information and interface.
    def InitUI(self):

        self.suspectCards = [Card("Miss Scarlet", "Card_MissScarlet.png", "smallCard_MissScarlet.png"),
                             Card("Colonel Mustard", "Card_ColonelMustard.png", "smallCard_ColonelMustard.png"),
                             Card("Mrs. White", "Card_MrsWhite.png", "smallCard_MrsWhite.png"),
                             Card("Mr. Green", "Card_MrGreen.png", "smallCard_MrGreen.png"),
                             Card("Mrs. Peacock", "Card_MrsPeacock.png", "smallCard_MrsPeacock.png"),
                             Card("Professor Plum", "Card_ProfPlum.png", "smallCard_ProfPlum.png")]

        self.roomCards = [Card("Study", "Card_Study.png", "smallCard_Study.png"),
                          Card("Hall", "Card_Hall.png", "smallCard_Hall.png"),
                          Card("Lounge", "Card_Lounge.png", "smallCard_Lounge.png"),
                          Card("Dining Room", "Card_DiningRoom.png", "smallCard_DiningRoom.png"),
                          Card("Kitchen", "Card_Kitchen.png", "smallCard_Kitchen.png"),
                          Card("Ballroom", "Card_Ballroom.png", "smallCard_Ballroom.png"),
                          Card("Conservatory", "Card_Conservatory.png", "smallCard_Conservatory.png"),
                          Card("Library", "Card_Library.png", "smallCard_Library.png"),
                          Card("Billiard Room", "Card_BilliardRoom.png", "smallCard_BilliardRoom.png")]

        self.weaponCards = [Card("Candlestick", "Card_Candlestick.png", "smallCard_Candlestick.png"),
                            Card("Knife", "Card_Knife.png", "smallCard_Knife.png"),
                            Card("Lead Pipe", "Card_LeadPipe.png", "smallCard_LeadPipe.png"),
                            Card("Revolver", "Card_Revolver.png", "smallCard_Revolver.png"),
                            Card("Rope", "Card_Rope.png", "smallCard_Rope.png"),
                            Card("Wrench", "Card_Wrench.png", "smallCard_Wrench.png")]


#    0   1   2   3   4   5   6
# 0                  S0		
# 
# 1     [R0]-H0-[R1]-H2-[R2]
#        |       |       |
# 2  S5  H11     H1      H3  S1
#        |       |       |
# 3     [R7]-H10[R8]-H4-[R3]
#        |       |       |
# 4  S4  H9      H7      H5
#        |       |       |   
# 5     [R6]-H8-[R5]-H6-[R4]
#  
# 6          S3      S2	

        self.rooms = [Room(self.p2, (25, 30), "Study", "Study.png"),
                      Room(self.p2, (225, 30), "Hall", "Hall.png"),
                      Room(self.p2, (425, 30), "Lounge", "Lounge.png"),
                      Room(self.p2, (425, 230), "Dining Room", "DiningRoom.png"),
                      Room(self.p2, (425, 430), "Kitchen", "Kitchen.png"),
                      Room(self.p2, (225, 430), "Ballroom", "Ballroom.png"),
                      Room(self.p2, (25, 430), "Conservatory", "Conservatory.png"),
                      Room(self.p2, (25, 230), "Library", "Library.png"),
                      Room(self.p2, (225, 230), "Billiard Room", "BilliardRoom.png")]
        
        for i in range(len(self.rooms)):
            for j in range(len(self.rooms[i].pieceLocations)):
                self.rooms[i].pieceLocations[j].setLocationPlace(self.rooms[i])

        for r in self.rooms:
            r.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterPlace)
            r.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeavePlace)


        self.hallways = [Hallway(self.p2, (175, 80)),
                         Hallway(self.p2, (275, 180)),
                         Hallway(self.p2, (375, 80)),
                         Hallway(self.p2, (475, 180)),
                         Hallway(self.p2, (375, 280)),
                         Hallway(self.p2, (475, 380)),
                         Hallway(self.p2, (375, 480)),
                         Hallway(self.p2, (275, 380)),
                         Hallway(self.p2, (175, 480)),
                         Hallway(self.p2, (75, 380)),
                         Hallway(self.p2, (175, 280)),
                         Hallway(self.p2, (75, 180))]

        for i in range(len(self.hallways)):
            self.hallways[i].pieceLocations[0].setLocationPlace(self.hallways[i])


        self.startingPlaces = [StartingPlace(self.p2, (388, 40)),
                               StartingPlace(self.p2, (526, 185)),
                               StartingPlace(self.p2, (388, 530)),
                               StartingPlace(self.p2, (188, 530)),
                               StartingPlace(self.p2, (51, 385)),
                               StartingPlace(self.p2, (51, 185))]

        self.pawns = [Pawn("Miss Scarlet", "MissScarlet1.png", self.sb),
                      Pawn("Colonel Mustard", "ColonelMustard1.png", self.sb),
                      Pawn("Mrs. White", "MrsWhite1.png", self.sb),
                      Pawn("Mr. Green", "MrGreen1.png", self.sb),
                      Pawn("Mrs. Peacock", "MrsPeacock1.png", self.sb),
                      Pawn("Professor Plum", "ProfPlum1.png", self.sb)]

        for i in range(len(self.startingPlaces)):
            self.startingPlaces[i].pieceLocations[0].addPieceToLocation(self.pawns[i])
        
        for i in range(len(self.pawns)):
            self.pawns[i].setPiecePlace(self.startingPlaces[i])
            self.pawns[i].setPieceLocation(self.startingPlaces[i].pieceLocations[0])
            self.pawns[i].setPieceBitmap()
        
        self.weapons = [Weapon("Candlestick", "Candlestick.png", self.sb),
                        Weapon("Knife", "Knife.png", self.sb),
                        Weapon("Lead Pipe", "LeadPipe.png", self.sb),
                        Weapon("Revolver", "Revolver.png", self.sb),
                        Weapon("Rope", "Rope.png", self.sb),
                        Weapon("Wrench", "Wrench.png", self.sb)]
        
        initialRoomsWithWeapon = random.sample(self.rooms, 6)
        w = []
        for i in range(len(initialRoomsWithWeapon)):
            w.append(random.randint(0, 11))
            initialRoomsWithWeapon[i].pieceLocations[w[i]].addPieceToLocation(self.weapons[i])

        for i in range(len(self.weapons)):
            self.weapons[i].setPieceLocation(initialRoomsWithWeapon[i].pieceLocations[w[i]])
            self.weapons[i].setPieceBitmap()

        self.startingPlaces[0].addAdjacentPlace(self.hallways[2])
        self.startingPlaces[1].addAdjacentPlace(self.hallways[3])
        self.startingPlaces[2].addAdjacentPlace(self.hallways[6])
        self.startingPlaces[3].addAdjacentPlace(self.hallways[8])
        self.startingPlaces[4].addAdjacentPlace(self.hallways[9])
        self.startingPlaces[5].addAdjacentPlace(self.hallways[11])
        	
        self.rooms[0].addAdjacentPlace(self.hallways[0])
        self.rooms[0].addAdjacentPlace(self.hallways[11])
        self.rooms[0].addAdjacentPlace(self.rooms[4])
        self.rooms[1].addAdjacentPlace(self.hallways[0])
        self.rooms[1].addAdjacentPlace(self.hallways[1])
        self.rooms[1].addAdjacentPlace(self.hallways[2])
        self.rooms[2].addAdjacentPlace(self.hallways[2])
        self.rooms[2].addAdjacentPlace(self.hallways[3])
        self.rooms[2].addAdjacentPlace(self.rooms[6])
        self.rooms[3].addAdjacentPlace(self.hallways[3])
        self.rooms[3].addAdjacentPlace(self.hallways[4])
        self.rooms[3].addAdjacentPlace(self.hallways[5])
        self.rooms[4].addAdjacentPlace(self.hallways[5])
        self.rooms[4].addAdjacentPlace(self.hallways[6])
        self.rooms[4].addAdjacentPlace(self.rooms[0])
        self.rooms[5].addAdjacentPlace(self.hallways[6])
        self.rooms[5].addAdjacentPlace(self.hallways[7])
        self.rooms[5].addAdjacentPlace(self.hallways[8])
        self.rooms[6].addAdjacentPlace(self.hallways[8])
        self.rooms[6].addAdjacentPlace(self.hallways[9])
        self.rooms[6].addAdjacentPlace(self.rooms[2])
        self.rooms[7].addAdjacentPlace(self.hallways[9])
        self.rooms[7].addAdjacentPlace(self.hallways[10])
        self.rooms[7].addAdjacentPlace(self.hallways[11])
        self.rooms[8].addAdjacentPlace(self.hallways[1])
        self.rooms[8].addAdjacentPlace(self.hallways[4])
        self.rooms[8].addAdjacentPlace(self.hallways[7])
        self.rooms[8].addAdjacentPlace(self.hallways[10])
    
        self.hallways[0].addAdjacentPlace(self.rooms[0])
        self.hallways[0].addAdjacentPlace(self.rooms[1])
        self.hallways[1].addAdjacentPlace(self.rooms[1])
        self.hallways[1].addAdjacentPlace(self.rooms[8])
        self.hallways[2].addAdjacentPlace(self.rooms[1])
        self.hallways[2].addAdjacentPlace(self.rooms[2])
        self.hallways[3].addAdjacentPlace(self.rooms[2])
        self.hallways[3].addAdjacentPlace(self.rooms[3])
        self.hallways[4].addAdjacentPlace(self.rooms[3])
        self.hallways[4].addAdjacentPlace(self.rooms[8])
        self.hallways[5].addAdjacentPlace(self.rooms[3])
        self.hallways[5].addAdjacentPlace(self.rooms[4])
        self.hallways[6].addAdjacentPlace(self.rooms[4])
        self.hallways[6].addAdjacentPlace(self.rooms[5])
        self.hallways[7].addAdjacentPlace(self.rooms[5])
        self.hallways[7].addAdjacentPlace(self.rooms[8])
        self.hallways[8].addAdjacentPlace(self.rooms[5])
        self.hallways[8].addAdjacentPlace(self.rooms[6])
        self.hallways[9].addAdjacentPlace(self.rooms[6])
        self.hallways[9].addAdjacentPlace(self.rooms[7])
        self.hallways[10].addAdjacentPlace(self.rooms[7])
        self.hallways[10].addAdjacentPlace(self.rooms[8])
        self.hallways[11].addAdjacentPlace(self.rooms[7])
        self.hallways[11].addAdjacentPlace(self.rooms[0])

#-----------------------------------------------------------------
#Runs the game.
#Backend needs to be implemented.
    def Play(self):

#        self.Test1()
        self.Test2()        

#Test Begins
    #Testing Join interface.
    def Test2(self):
        MISS_SCARLET = 0
        COLONEL_MUSTARD = 1
        MRS_WHITE = 2
        MR_GREEN = 3
        MRS_PEACOCK = 4
        PROFESSOR_PLUM = 5

        self.joinButton.Bind(wx.EVT_BUTTON, self.OnJoin)

        self.caseFile = ["Mr. Green", "Study", "Revolver"]

        c0 = [self.suspectCards[3], self.roomCards[1], self.weaponCards[4]]
        c1 = [self.suspectCards[5], self.roomCards[3], self.weaponCards[0]]
        c2 = [self.suspectCards[1], self.roomCards[7], self.weaponCards[2]]
        c3 = [self.suspectCards[4], self.roomCards[6], self.weaponCards[5]]
        c4 = [self.suspectCards[0], self.roomCards[5], self.weaponCards[1]]
        c5 = [self.suspectCards[2], self.roomCards[8], self.weaponCards[3]]

        self.players = [Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MISS_SCARLET,
                               c1, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, COLONEL_MUSTARD,
                               c5, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MRS_WHITE,
                               c3, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MR_GREEN,
                               c2, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MRS_PEACOCK,
                               c0, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, PROFESSOR_PLUM,
                               c4, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile)]


        self.Status()

    #Testing Miss Scarlet's movement, suggestion, and responses.
    def Test1(self):
        MISS_SCARLET = 0
        COLONEL_MUSTARD = 1
        MRS_WHITE = 2
        MR_GREEN = 3
        MRS_PEACOCK = 4
        PROFESSOR_PLUM = 5

        c0 = [self.suspectCards[3], self.roomCards[1], self.weaponCards[4]]
        c1 = [self.suspectCards[5], self.roomCards[3], self.weaponCards[0]]
        c2 = [self.suspectCards[1], self.roomCards[7], self.weaponCards[2]]
        c3 = [self.suspectCards[4], self.roomCards[6], self.weaponCards[5]]
        c4 = [self.suspectCards[0], self.roomCards[5], self.weaponCards[1]]
        c5 = [self.suspectCards[2], self.roomCards[8], self.weaponCards[3]]

        self.caseFile = ["Mr. Green", "Study", "Revolver"]

        self.players = [Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MISS_SCARLET,
                               c1, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, COLONEL_MUSTARD,
                               c5, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MRS_WHITE,
                               c3, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MR_GREEN,
                               c2, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MRS_PEACOCK,
                               c0, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile),
                        Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, PROFESSOR_PLUM,
                               c4, self.accuseButton, self.suspectCards, self.roomCards, self.weaponCards, self.caseFile)]
        
        for i in range(len(self.players)):
            self.players[i].getPlayerPawn().setPawnPlayer(self.players[i])


#        self.players.append(Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MRS_PEACOCK, c1))
#        self.players.append(Player(self.startingPlaces, self.hallways, self.rooms, self.weapons, self.pawns, MISS_SCARLET, c2))

#Test Miss Scarlet movement

        self.players[4].playerPawn.pieceLocation.removePieceFromLocation()
        self.players[4].playerPawn.piecePlace = self.rooms[2]
        self.players[4].playerPawn.pieceLocation = self.rooms[2].pieceLocations[0]
        self.rooms[2].pieceLocations[0].addPieceToLocation(self.players[4].playerPawn)
        self.players[4].playerPawn.setPieceBitmap()
#        self.players[4].SetAdjacentPlacesToMove()
        
        self.players[0].getPlayerPawn().pieceLocation.removePieceFromLocation()
        self.players[0].getPlayerPawn().piecePlace = self.hallways[3]
        self.players[0].getPlayerPawn().setPieceLocation(self.hallways[3].pieceLocations[0])
        self.players[0].getPlayerPawn().getPieceLocation().addPieceToLocation(self.players[0].playerPawn)
        self.players[0].getPlayerPawn().setPieceBitmap()

        playerCards = self.players[0].getPlayerCards()
        for i in range(len(playerCards)):
            self.cardPanels[i].addCard(playerCards[i])
            sb = self.cardPanels[i].getCardStaticBitmap()
            sb.SetBitmap(playerCards[i].getSmallCardBitmap())

        self.players[0].SetAccuseButtonAvailable()
        self.players[0].SetAdjacentPlacesToMove()

        self.Status()
#Test Ends
    def Status(self):
        for h in self.hallways:
            h.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterPlace)
            h.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeavePlace)

        for p in self.pawns:
            p.pieceLocation.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterPiece)
            p.pieceLocation.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeavePiece)

        for w in self.weapons:
            w.pieceLocation.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterPiece)
            w.pieceLocation.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeavePiece)

        for c in self.cardPanels:
            c.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterCard)
            c.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveCard)

#-----------------------------------------------------------------
#Methods that repsponds to various events.
    def OnAbout(self, event):
        d = wx.MessageDialog(self, "Clue-Less game for Foundation of Software Engineering Group Project.")
        d.ShowModal()
        d.Destroy()

    #Joining Game.
    def OnJoin(self, event):
        print "Join the game."
        a = JoinDialog(None, -1, 'Join the game', self.suspectCards, self.p1, self.playerCardPanel, self.playerPawnName, self.players)
        a.ShowModal()
        a.Destroy()
        return True

    def OnExit(self, event):
        self.Close(True)

    def OnEnterPiece(self, event): 
        name = event.GetEventObject().pieceInLocation.getPieceName()
        self.sb.SetStatusText(name)
        event.Skip()

    def OnLeavePiece(self, event):
        self.sb.SetStatusText("")
        event.Skip()

    def OnEnterPlace(self, event):
        name = event.GetEventObject().getPlaceName()
        self.sb.SetStatusText(name)
        event.Skip()

    def OnLeavePlace(self, event):
        self.sb.SetStatusText("")
        event.Skip()

    def OnEnterCard(self, event):
        e = event.GetEventObject()
        if e.isEmptyOfCard == True:
            self.sb.SetStatusText("")
        elif e.isEmptyOfCard == False:
            name = e.getCard().getCardName()
            self.sb.SetStatusText(name)
        event.Skip()

    def OnLeaveCard(self, event):
        self.sb.SetStatusText("")
        event.Skip()

def main(n, host_address, host_port = None):
    port = int(host_port) if host_port is not None else 50007
    s = socket.create_connection((host_address, port))

    global g_client
    g_client = launch_thread(client.CluelessClient, 'client %s' % n)
    p = proxy_receiver.ProxyReceiver( 'client %s receiver' % n, g_client[ 1 ], s)
    p.start()

    ntfy(g_client, 'connect_to_server', proxy_sender.QueueWrapper(s))

    if '0' in n:
        ntfy(g_client, 'new_game', g_game_id)

    app = wx.App(False)
    GameInterface(None, 'Clue-less')
    app.MainLoop()
    
 
#-----------------------------------------------------------------
if __name__ == '__main__':
    if len(sys.argv) <= 2:
        print 'Usage: python game.py id host-address [host-port]'
    else:
        main(*sys.argv[1:])
